package com.huawei.hianalytics.ab.bc.ik.bc;

import com.huawei.hianalytics.ab.ab.bc;
import com.huawei.hianalytics.ab.bc.ik.cd.ab;
import com.huawei.hianalytics.ab.bc.kl.ef;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;

public class de implements ab {
    private String ab;
    private String bc;
    private String cd;
    private List<com.huawei.hianalytics.ab.bc.cd.bc.de> de;

    public de(List<com.huawei.hianalytics.ab.bc.cd.bc.de> list, String str, String str2, String str3) {
        this.ab = str;
        this.bc = str2;
        this.cd = str3;
        this.de = list;
    }

    private void ab() {
        String ab = ef.ab(this.ab, this.cd, this.bc);
        com.huawei.hianalytics.ab.bc.ij.ab.ab(bc.ik(), "backup_event", ab);
    }

    public void run() {
        if (this.de == null || this.de.size() == 0) {
            com.huawei.hianalytics.ab.bc.ef.ab.bc("FailedEventHandlerTask", "failed events is empty");
            return;
        }
        if (com.huawei.hianalytics.ab.bc.kl.bc.ab(bc.ik(), "cached_v2_1", bc.ij() * 1048576)) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("FailedEventHandlerTask", "The cacheFile is full,Can not writing data! reqID:" + this.bc);
            return;
        }
        String ab = ef.ab(this.ab, this.cd);
        List list = (List) com.huawei.hianalytics.ab.bc.de.ef.bc(bc.ik(), "cached_v2_1", ab).get(ab);
        if (!(list == null || list.size() == 0)) {
            this.de.addAll(list);
        }
        JSONArray jSONArray = new JSONArray();
        for (com.huawei.hianalytics.ab.bc.cd.bc.de de : this.de) {
            try {
                jSONArray.put(de.de());
            } catch (JSONException e) {
                com.huawei.hianalytics.ab.bc.ef.ab.cd("FailedEventHandlerTask", "event to json error");
            }
        }
        com.huawei.hianalytics.ab.bc.ef.ab.bc("FailedEventHandlerTask", "data send failed, write to cache file...reqID:" + this.bc);
        com.huawei.hianalytics.ab.bc.ij.ab.ab(bc.ik(), "cached_v2_1", ab, jSONArray.toString());
        ab();
    }
}
